package com.zmn.oms.third.yajule;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * 雅居乐平台渠道常量参数
 *
 * @author xiewenbing
 * @date 2020/07/31
 */
@Component
public class YajuleConsts {

    /**
     * 渠道名称
     */
    public final static String CHANNEL_NAME="雅居乐-API";

    /**
     * 版本号
     */
    public final static String APP_VER="1.0";

    /**
     * 成功的结果码
     */
    public final static int CODE_SUCCESS = 0;

    /**
     * 支付状态:未支付
     */
    public final static int PAY_RESULT_UNDO=1;

    /**
     * 支付状态:部分支付
     */
    public final static int PAY_RESULT_PART=2;

    /**
     * 支付状态:已支付
     */
    public final static int PAY_RESULT_DONE=3;

    /**
     * 支付状态:退回
     */
    public final static int PAY_RESULT_BACK=4;

    /**
     * 支付方式:雅居乐
     */
    public final static int PAY_WAY_SELF=0;

    /**
     * 支付方式:支付宝
     */
    public final static int PAY_WAY_ALIPAY=1;

    /**
     * 支付方式:雅居乐
     */
    public final static int PAY_WAY_WECHAT=2;

    /**
     * 支付方式:银联
     */
    public final static int PAY_WAY_UNIONPAY=3;

    /**
     * 支付方式:安吉拉
     */
    public final static int PAY_WAY_AJILA=4;

    /**
     * 支付方式:微信公众号
     */
    public final static int PAY_WAY_MP_WECHAT=5;

    /**
     * 获取支付链接的method
     */
    public final static String GET_PAY_URL_METHOD="base.paymentCoop.unifiedorderQrCode";

    /**
     * 雅居乐API URL
     */
    public static String API_URL="https://api.4006983383.com/api.do";

    /**
     * 雅居乐APP ID
     */
    public static String APP_ID = "03608cce148145889cb79a86e6f83355";

    /**
     * 雅居乐APP SECRET
     */
    public static String APP_SECRET = "WYCBBgHZHTlSNQ3PTY6WZLNhRV75Y0ImaeCjAswgs6wvNjbcW3RKpZ0XNqbFMF84";

    /**
     * 雅居乐RSA 数据解密public key
     */
    public static String RSA_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCF07IBVcZ5tF5upD+TzxeIS9QttE7InVuJqaN8hhiXLJ9s5hSeyH9FL9WUVM2qeGg+6eQ6TowPIIF9l8bt3aqOSJdN76L+dXsgW3A5Ek/GFKoqdiZdChUzL9TtVzuKa59oQbWDtbDsWo6kicqEtBAy5LiIeGoMdd5mMiFJigLpxwIDAQAB";

    /**
     * 收款账户UID
     */
    public static String BENEFICIARY_UID = "8EA5BDB8A49D485884ECDF82E4CCF5A9";

    /**
     * 支付回调地址
     */
    public static String CALL_URL = "https://api-oms.xiujiadian.com/yajule/api/syncOrderPay";

    /**
     * 雅居乐的渠道列表
     */
    public static List<Integer> CHANNEL_ID_LIST = Arrays.asList(1381,1446,10677,10678,10679,10680,10681,31047,31048);

    /**
     * 获取支付方式的说明
     * @param payWay
     * @return
     */
    public static String getPayWay(int payWay) {

        switch (payWay) {
            case PAY_WAY_SELF:
                return "雅居乐平台";
            case PAY_WAY_ALIPAY:
                return "支付宝";
            case PAY_WAY_WECHAT:
                return "微信";
            case PAY_WAY_UNIONPAY:
                return "银联";
            case PAY_WAY_AJILA:
                return "安吉拉";
            case PAY_WAY_MP_WECHAT:
                return "微信公众号";
        }

        return "Unknown Pay Way";
    }

    public static String getPayStatus(int payStatus) {

        switch (payStatus) {
            case PAY_RESULT_UNDO:
                return "未支付";
            case PAY_RESULT_PART:
                return "部分支付";
            case PAY_RESULT_DONE:
                return "支付完成";
            case PAY_RESULT_BACK:
                return "已退回";
        }

        return "Unknown Pay Status";
    }

    /**
     * 判断是否属于雅居乐渠道
     * @param channelId
     * @return
     */
    public static boolean isYajuleChannel(Integer channelId) {
        return CHANNEL_ID_LIST.contains(channelId);
    }

    @Value("${yajule.api.url:https://api.4006983383.com/api.do}")
    public void setApiUrl(String apiUrl) {
        API_URL = apiUrl;
    }

    @Value("${yajule.app.id:03608cce148145889cb79a86e6f83355}")
    public void setAppId(String appId) {
        APP_ID = appId;
    }

    @Value("${yajule.app.secret:WYCBBgHZHTlSNQ3PTY6WZLNhRV75Y0ImaeCjAswgs6wvNjbcW3RKpZ0XNqbFMF84}")
    public void setAppSecret(String appSecret) {
        APP_SECRET = appSecret;
    }

    @Value("${yajule.app.rsakey:MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCF07IBVcZ5tF5upD+TzxeIS9QttE7InVuJqaN8hhiXLJ9s5hSeyH9FL9WUVM2qeGg+6eQ6TowPIIF9l8bt3aqOSJdN76L+dXsgW3A5Ek/GFKoqdiZdChUzL9TtVzuKa59oQbWDtbDsWo6kicqEtBAy5LiIeGoMdd5mMiFJigLpxwIDAQAB}")
    public void setRsaKey(String rsaKey) {
        RSA_KEY = rsaKey;
    }

    @Value("${yajule.app.buid:8EA5BDB8A49D485884ECDF82E4CCF5A9}")
    public void setBeneficiaryUid(String beneficiaryUid) {
        BENEFICIARY_UID = beneficiaryUid;
    }

    @Value("${yajule.app.callurl:https://api-oms.xiujiadian.com/yajule/api/syncOrderPay}")
    public void setCallbackUrl(String callUrl) {
        CALL_URL = callUrl;
    }
}
